Skip to main content

Run a Report with XML Data in the Java Embedded Engine

This tutorial will guide you through running a document with XML data in the Java Embedded Engine. It will go over installing the Java Embedded Engine, and setting up the code to run a report with XML data.

tip

Before installation of the Java Embedded Engine, make sure you meet the requirements and have the necessary pre-requisites installed. Those can be found here.

Install the Java Embedded Engine

There are two ways to install the Java Embedded Engine.

  1. Maven
  2. Manual Installation with zip file

Maven

To include the Java Engine in your project via Maven, follow the instructions found here.

Manual Installation with zip file

The other approach is referencing the Java Embedded Engine by downloading the zip file which contains the necessary JARs. These can be found on our downloads page here.

Once you have downloaded the zip file, extract the contents and reference the JARs in your project. The steps to do this can be found here.

Setup the Properties

Once you have installed the Java Embedded Engine, you will need to set up the necessary properties in the properties file so you can generate documents. In your projects resources directory, create a file called "WindwardReports.properties". This file will contain the properties related to document generation. The only property that is required to get started is the license. If this is empty you can still generate output, however it will contain a watermark.

To add your license key or any report properties, you need to add a WindwardReports section to your projects WindwardReports.properties file:

license=[[LICENSE]]
tip

To learn more about the different properties we provide for report generation, check out this article.

Generating a Document

Now that you have the Java Embedded Engine installed and the properties set up, you can start generating documents. Below is an example of how to generate a document with XML data.

import net.windward.datasource.DataSourceProvider;
import net.windward.datasource.xml.SaxonDataSource;
import net.windward.xmlreport.ProcessPdf;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class JavaXmlSample {
public static void main(String[] args) {
try {
// To generate a report, first we need a ProcessReport object. For now, we're using the
// pdf format to output.
File fileReport = new File("report.pdf");
FileInputStream template = new FileInputStream("XML - Template.docx");
FileOutputStream reportStream = new FileOutputStream(fileReport);
ProcessPdf report = new ProcessPdf(template, reportStream);

// Preparation...
report.processSetup();

// Set up the datasource.
String url = "http://xml.windward.net/southwind.xml"; // The URL of the XML file
String xsd = null; // The URL of the XSD file (null if not applicable)
DataSourceProvider datasource = new SaxonDataSource(url, xsd);

// Finally, send it to Windward for processing. The second parameter is the name of the
// datasource. This should match the name used in your template.
report.processData(datasource, "XmlData");

// And... DONE!
report.processComplete();

template.close();
reportStream.close();

} catch (Exception e) {
// Uh oh, just in case
e.printStackTrace();
}
}
}